/**
 * Author: wangxiaoying
 * Email: 1009929414@qq.com
 * Description:金钱格式化
 */

const formatMoney = {

  //保留两位小数（四舍五入）
  twoDecimal(money) {
    if (typeof money === "string") {
      money = money.replace(/,/g, "")
    }
    money = Number(money) ? (Math.round(Number(money) * 100) / 100).toFixed(2) : "0.00";
    return money.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
      return $1 + ",";
    });
  },

  // 转化为纯数值
  toNumber(money) {
    if (typeof money === "string") {
      money = money.replace(/,/g, "")
    }
    return Number(money) ? Number(money) : 0
  }
}
export default formatMoney;
